<template>
  <div class="couponList">
    <ball-header :leftArrow="false" title="优惠券列表" :border="false" z-index="5">
      <div slot="left" @click="$router.back(-1)"><van-icon name="arrow-left" size="24" color="#000000" /></div>
    </ball-header>
    <div class="container">
      <div class="item" v-for="(item,index) in couponList" :key="index">
        <div class="item_content acea-row row-middle">
          <div class="item_head" :class="item.istimevalid!=0?'item_head_color1':'item_head_color2'">
            <h2 class="item_amount">
              {{item.coupon_price}}<span>元</span>
            </h2>
            <div class="item_condition">
              <p>{{item.use_min_price==0?"无使用门栏":"满"+item.use_min_price+"元可用"}}</p>
              <p>最多优惠{{item.coupon_price}}元</p>
            </div>
          </div>
          <div class="item_body">
            <p class="item_name">{{item.coupon_title}}</p>
            <p class="item_valid" v-if="item.startAt">{{moment(item.startAt*1000).format("YYYY年MM月DD日")}} - {{moment(item.endAt*1000).format("YYYY年MM月DD日")}}</p>
            <p class="item_valid" v-else>无时限</p>
          </div>
        </div>
        <div class="item_description">{{changeStatus(item)}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import ballHeader from 'components/header'
import api from 'api'
import moment from 'moment'

export default {
  components:{
    ballHeader
  },
  data() {
    return {
      couponList:[],
      moment
    }
  },
  activated() {
    this.getCoupons()
  },
  methods: {
    getCoupons(){
      api.get("/order/getCoupons").then(e=>{
        this.couponList = e.data
      })
    },
    changeStatus(i){
      if(i.istimevalid == 0 || i.usetype == 4){
        return "不可用"
      }else if(i.usetype == 1){
        return "订场可用"
      }else if(i.usetype == 2){
        return "套餐可用"
      }else{
        return "可用"
      }
    }
  },
}
</script>

<style scoped>
  .couponList{
    min-height: 100vh;
    background-color: #f2f3f5;
  }
  .container{
    width: 690px;
    min-height: calc(100vh - 122px);
    margin: 30px auto 0;
  }
  .container .item{
    width: 100%;
    background-color: #ffffff;
    border-radius: 16px;
    margin-bottom: 24px;
    box-shadow: 0 0 8px rgb(0 0 0 / 10%);
    overflow: hidden;
  }
  .container .item .item_content{
    padding: 28px 0;
    color: #323233;
    box-sizing: border-box;
    min-height: 168px;
  }
  .container .item .item_content .item_head{
    position: relative;
    min-width: 192px;
    padding: 0 16px;
    text-align: center;
  }
  .container .item .item_content .item_head.item_head_color1{
    color: #ee0a24;
  }
  .container .item .item_content .item_head.item_head_color2{
    color: inherit;
  }
  .container .item .item_content .item_head .item_amount{
    margin-bottom: 12px;
    font-weight: 500;
    font-size: 60px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .container .item .item_content .item_head .item_amount span{
    font-weight: normal;
    font-size: 40%;
    margin-left: 4px;
  }
  .container .item .item_content .item_head .item_condition{
    font-size: 24px;
    line-height: 32px;
    white-space: pre-wrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .container .item .item_content .item_body{
    position: relative;
    flex: 1;
    border-radius: 0 16px 16px 0;
  }
  .container .item .item_content .item_body .item_name{
    margin-bottom: 20px;
    font-weight: bold;
    font-size: 28px;
    line-height: 40px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .container .item .item_content .item_body .item_valid{
    font-size: 24px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .container .item .item_description{
    padding: 16px 32px;
    font-size: 24px;
    border-top: 2px dashed #ebedf0;
  }
</style>